'''
    自动取款机系统系统
    1.登陆
    2.查看余额
    3.存钱
    4.取钱
    5.界面和交互
'''


#登陆信息数据源
user_list = [
    {'user_name':'zhangsan','Password':123456,'Balance':10000},
    {'user_name':'lisi','Password':456789,'Balance':20000},
    {'user_name':'wangwu','Password':789123,'Balance':30000}]

#1.登陆功能
def user_login(user,password):
    for user_id in range(len(user_list)):

        if user == user_list[user_id]['user_name']:
            if password == user_list[user_id]['Password']:

                print('欢迎使用',user)
                return user_id
            else:
                print('密码错误')
                return -1
    print('此账号不存在')
    return -2

# user_login('zhangsan',123456)


#2.查看余额
def cha_Balance(user_id):
    user = user_list[user_id]['user_name']
    balance = user_list[user_id]['Balance']
    print('{}您的账户余额为{}元'.format(user,balance))



#3.存钱
def add_Balance(user_id):
    while True:
        money = int(input('请输入要存入的金额'))
        if money <= 0:
            print('请输入正确金额')
        else:
            balance = user_list[user_id]['Balance']
            balance += money
            print('成功存入{}元，当前余额{}元'.format(money,balance))
            break



#4.取钱
def del_Balance(user_id):
    while True:
        money = int(input('请输入要取出的金额'))
        balance = user_list[user_id]['Balance']
        if money <= 0:
            print('请输入正确金额')

        elif money > balance:
            print('余额不足')

        else:
            balance -= money
            print('成功取款{}元，当前余额{}元'.format(money, balance))
            break


#5.界面和交互
while True:
    #登陆界面
    print('=' * 12, '自动取款机', '=' * 12)
    user = input('请输入用户名')
    password = int(input('请输入密码'))

    user_id = user_login(user,password)
    if user_id < 0:
        continue

    while True:
        print('=' * 12, '请选择业务', '=' * 12)
        print('{:1} {:13} {:10}'.format(' ', '1、余额查询', '2、存款'))
        print('{:1} {:13} {:10}'.format(' ', '3、取款', '4、退出系统'))

        key = input('请输入对应的选择')
        # 根据输入操作值，执行对应操作
        if key == '1':
            print('=' * 12, '余额查询', '=' * 12)
            cha_Balance(user_id)
            input('按回车继续:')
        elif key == '2':
            print('=' * 12, '存款', '=' * 12)
            add_Balance(user_id)
            input('按回车继续:')
        elif key == '3':
            print('=' * 12, '取款', '=' * 12)
            del_Balance(user_id)
            input('按回车继续:')
        elif key == '4':
            print('=' * 12, '再见', '=' * 12)
            break
        else:
            print('=' * 12, '操作无效', '=' * 12)


    break







